package com.cyh.pangu.offer;

import com.cyh.pangu.offer.common.ListNode;

public class Offer18 {

    public ListNode deleteNode(ListNode head, int val) {
        if (head == null) {
            return head;
        }

        if (head.val == val) {
            return head.next;
        }

        ListNode currentNode = head;

        ListNode nextNode = head.next;

        while (nextNode != null) {
            if (nextNode.val == val) {
                currentNode.next = nextNode.next;
                break;
            } else {
                currentNode = nextNode;
                nextNode = nextNode.next;
            }
        }

        return head;
    }

}
